package com.example.hcbmsm.service;

import com.alibaba.fastjson.JSONObject;
import com.example.hcbmsm.mapper.AnalyzeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AnalyzeService {

    @Autowired
    private AnalyzeMapper analyzeMapper;

    public JSONObject getData1(){
        JSONObject data = new JSONObject();
        List<JSONObject> data1 = analyzeMapper.getData1();
        List<String> names = new ArrayList<>();
        List<Integer> values = new ArrayList<>();
        for (JSONObject jsonObject : data1) {
            String name = jsonObject.getString("name");
            names.add(name);
            Integer value = jsonObject.getInteger("value");
            values.add(value);
        }
        data.put("names",names);
        data.put("values",values);
        return data;
    }

    public List<JSONObject> getData2(){
        return analyzeMapper.getData2();
    }






    public JSONObject getData3(){
        JSONObject data = new JSONObject();
        List<JSONObject> data1 = analyzeMapper.getData3();
        List<String> names = new ArrayList<>();
        List<Integer> values = new ArrayList<>();
        for (JSONObject jsonObject : data1) {
            String name = jsonObject.getString("day");
            names.add(name);
            Integer value = jsonObject.getInteger("money");
            values.add(value);
        }
        data.put("names",names);
        data.put("values",values);
        return data;
    }

}
